package com.chinasoft.reposearch.controller;


import com.chinasoft.reposearch.entity.ResponseResult;
import com.chinasoft.reposearch.entity.po.TopicCount;
import com.chinasoft.reposearch.service.TopicCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequiredArgsConstructor
@CrossOrigin
public class TopicController {
    public final TopicCountService topicCountService;
    @Autowired
    public TopicController(TopicCountService topicCountService) {
        this.topicCountService = topicCountService;
    }

    /**
     * GET /topic-counts?year=yyyy&month=mm
     * 查询所有主题 某一年月的 列表和数量
     */
    @GetMapping("/topic-counts")
    public ResponseResult getTopicCounts(@RequestParam(required = false) Integer year, @RequestParam(required = false) Integer month) {
        return topicCountService.getTopicCounts(year, month);
    }

    /**
     * GET /topic-trending?topic=xxxx&year=yyyy
     * 查询某一主题 在所有年月的 列表和数量
     */
    @GetMapping("/topic-trending")
    public List<TopicCount> getTopicTrending(@RequestParam(required = false) String topic, @RequestParam(required = false) Integer year) {
        return topicCountService.getTopicTrending(topic, year);
    }

    @GetMapping("/topics")
    public List<String> getTopics() {
        return topicCountService.getTopics();
    }

    @GetMapping("/topic-trending-years")
    public List<TopicCount> getTopicTrendingYears(String topic, Integer start, Integer end) {
        return topicCountService.getTopicTrendingYears(topic, start, end);
    }
}

